package com.bo.gather.rule;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import com.bo.gather.bean.GatherBean;

public class RuleService {
	public GatherBean calculateRule(String rulestr){
		GatherRule gatherRule=new GatherRule();
		GatherBean gatherbean=new GatherBean();
		
		//切分格式内容 先切父节点
		int childurlindex=rulestr.indexOf(GatherRule.gatherchildurl);
		if(childurlindex!=-1){
			String parentstr=rulestr.substring(0, childurlindex);
			gatherRule.calculateParentNote(parentstr, gatherbean);
		}
//		System.out.println(parentstr);
		//切分格式内容 切子节点
		int weibotitleindex=rulestr.indexOf(BaseRule.weibotitle);
		if(weibotitleindex!=-1){
			String childstr=rulestr.substring(childurlindex, weibotitleindex);
			gatherRule.calculateChildNote(childstr, gatherbean);
		}
//		System.out.println(childstr);
		
		//切分格式内容 切微博节点
//		int weiborandomindex=rulestr.indexOf(GatherRule.weiborandom);
		if(weibotitleindex!=-1){
			String weibostr=rulestr.substring(weibotitleindex, rulestr.length());
			WeiboRule weiboRule=new WeiboRule();
			gatherbean.setWeiboRuleBean(weiboRule.calculateWeiboNote(weibostr));
		}
//		System.out.println(weibostr);
		
		
		
		return gatherbean;
	}
	
//	
//	public static  String readFile( File file) {
//		BufferedReader in = null;
//		String currLine = null;
////		List<String> ruleList=new ArrayList<String>();
//		StringBuffer sb=new StringBuffer();
//		try {
//			in = new BufferedReader(new FileReader(file));
//			while ((currLine = in.readLine()) != null) {
//				if (currLine.trim().equals("")) {
//					continue;
//				}
//				sb.append(currLine);
//				sb.append("\n");
////				ruleList.add(currLine);
////				System.out.println(currLine);
////				String rowValues[] = currLine.split(separateTab);
//			}	
//		}catch(Exception io){
//			io.printStackTrace();
//		} finally {
//			try {
//				in.close();
//			} catch (IOException ex) {				
//			}
//			in = null;
//		}
////		System.out.println(sb.toString());
//		return sb.toString();
//	}
	
	public static void main(String[] args) {
//		RuleService rule=new RuleService();
//		String rulestr=RuleService.readFile(new File("D:\\bo\\优酷.txt"));
//		rule.calculateRule(rulestr);
		
	}
}
